package com.weisy.signin.base;

import android.content.Context;
import android.os.Bundle;

import com.github.zackratos.ultimatebar.UltimateBar;
import com.weisy.signin.R;

import java.lang.ref.WeakReference;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import butterknife.ButterKnife;

/**
 * @author weisy
 * @function Activity基类
 * @date 2019/3/20 22:59
 */
public abstract class BaseAcativity extends AppCompatActivity {
    public final String TAG = this.getClass().getSimpleName();
    private boolean isFirst = true;
    public Context context;
    //是否在onResume中加载数据
    public boolean isResume = false;

    private boolean isBarDark = false;
    private int drawableId = R.drawable.gradient_main_bg;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context = new WeakReference<Context>(this).get();
        findView();
        ButterKnife.bind(this);
        UltimateBar.Companion.with(this)
                .statusDark(isBarDark)                  // 状态栏灰色模式(Android 6.0+)，默认 flase
                .statusDrawable(ContextCompat.getDrawable(context, drawableId))           // 状态栏背景，默认 null
                .statusDrawable2(ContextCompat.getDrawable(context, drawableId))         // Android 6.0 以下状态栏灰色模式时状态栏颜色
                .applyNavigation(false)              // 应用到导航栏，默认 flase
                .navigationDark(true)              // 导航栏灰色模式(Android 8.0+)，默认 false
                .create()
                .drawableBar();
        initView();
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (isFirst || isResume) {
            isFirst = false;
            initData();
        }
    }

    /**
     * 状态栏字体风格和背景
     *
     * @param isBarDark  false默认亮色风格
     * @param drawableId 背景drawable
     */
    public void setStatusStyle(boolean isBarDark, int drawableId) {
        this.isBarDark = isBarDark;
        this.drawableId = drawableId;
    }

    public abstract void findView();

    public abstract void initView();

    public abstract void initData();
}
